import java.util.InputMismatchException;
import java.util.Scanner;
public class InputIO {
	private Scanner sc=new Scanner(System.in);
	//==== input multi line =========
	public String inputMultiLine(){
		String str=new String();
		StringBuilder st=new StringBuilder();
		do{
			str=sc.nextLine();
			if(str!=null && str.trim().length()==1 && str.trim().contains("."))break;
			st.append(str+"\n");
		}while(true);
		return st.toString();
	}
	//==== input single line =========
	public String input(){
		String s=sc.nextLine();
		return s;
	}	
	//==== input only number =========
	public int inputNumber(){
		int d;
		do{
			try{
				d=sc.nextInt();
				if(d<0){
					System.out.println("Id can't input smaller than 1!!!!!");
					d=-2;
				}
				break;
			}
			catch(InputMismatchException e){
				System.out.println("Can't input character and space!!!!");
					return -2;
			}
			finally{
				sc.nextLine();
			}
		}while(true);
		return d;
	}
	//==== choose option for menu =========
	public String getOption(){
		String o="";
		String patt="1234567890rwdusepnmb";
		do{
			o=input();
			String str[]=o.split(" ");
			str[0]=str[0].toLowerCase();
			if(o.trim().length()>1){
				Main.shortcutString=o.substring(1,o.length());
				if(patt.contains(str[0]) && checkShortCut(str[0])){
					o=str[0];
					break;
				}
			}
			else if(o.trim().length()==1 && patt.contains(o)){
				break;
			}
			System.out.print("Choose: ");
		}while(true);
		return o.toLowerCase();
	}
	//==== check shortcut key =========
	private boolean checkShortCut(String c){
		boolean b=false;
		switch(c){
			case "w":if(b=CheckSWrite())ArticalProcess.SWrite=true;	
				     break;
			case "r":if(b=CheckNumber())ArticalProcess.SRead=true;
					 break;
			case "d":if(b=CheckNumber())ArticalProcess.SDelete=true;
					 break;
			case "u":if(b=CheckNumber())ArticalProcess.SUpdate=true;
					 break;
			case "s":if(b=CheckSearch())ArticalProcess.SFind=true;
					 break;
			case "n":if(b=CheckNumber())PaginationProcess.SNTP=true;
					  break;
			case "p":if(b=CheckNumber())PaginationProcess.SSetPage=true;break;
			
		}
		return b;
	}
	//==== check shortcut write =========
	private boolean CheckSWrite(){
		String s[]=Main.shortcutString.split("//");
		if(s.length<3){
			return false;
		}else{
			if(s[0]=="" ||s[1]=="" || s[2]=="")return false;
			return true;
		}
		
	}
	//==== check shortcut search =========
	private boolean CheckSearch(){
		if(Main.shortcutString.length()>0){
			return true;
		}
		return false;
	}
	//==== check id =========
	public int CheckId(int data){
		for(int i=0;i<Pagination.listNameFile.size();i++){
			if(Pagination.listNameFile.get(i)==data){
				return i;
			}
		}
		return -1;
	}
	//==== check number =========
	private boolean CheckNumber(){
		String s=Main.shortcutString.trim();
		if(!isNumber(s)){
			System.out.println("Id can't input character and space");
			return false;
		}
		return true;
	}
	//==== check number =========
	private boolean isNumber(String s){
		try  
		  {
		    int d = Integer.parseInt(s);
		  }catch(NumberFormatException e){
			  return false;
		  }
		return true;
	}
	//==== disply message continue or not =========
	public boolean ContinueOrNot(String str){
		System.out.print(str);
		String s=input();
		if(s.contains("y"))
			return true;
		return false;
	}
	
}
